package checkDistances;

import java.util.HashMap;
import java.util.Map;

public class Solution {
    public boolean checkDistances(String s, int[] distance) {
        // 第i个字母两次出现的距离相差dis[i].
        Map<Character,Integer> map = new HashMap<>();
        for (int i = 0; i < s.length(); i++) {
            char c = s.charAt(i);
            int index = map.getOrDefault(c,-1);
            if(index!=-1) {
                if(i - index -1!=distance[c-'a']){
                    return false;
                }
            }
            else {
                map.put(c,i);
            }
        }
        return true;
    }
}
